package guda.house.biz.form.village;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import guda.house.dal.dataobject.ParkingDO;
import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ParkingForm {

	@NotNull(message = "不能为空")
	@Size(min=1,max=10,message = "长度在1到10个字符之间")
	private String parkingName;

	@NotNull(message = "不能为空")
	private Long villageId;
	@Size(min=0,max=10,message = "长度在0到10个字符之间")
	private String ownerType;
	private Long ownerId;
	@Size(min=0,max=30,message = "长度在0到30个字符之间")
	private String parkingCard;
	@Size(min=0,max=10,message = "长度在0到10个字符之间")
	private String carNo;
	@Size(min=0,max=80,message = "长度在0到80个字符之间")
	private String memo;
	private String gmtStart;
	private String gmtEnd;

	@NotNull(message = "不能为空")
	private Long suiteId;

	private Long unitId;

	private Long buildingId;
	@NotNull(message = "不能为空")
	private Integer buyed;
	@NotNull(message = "不能为空")
	private Long parkingTypeId;



	public Integer getBuyed() {
		return buyed;
	}

	public void setBuyed(Integer buyed) {
		this.buyed = buyed;
	}

	public ParkingDO toDO() {
		ParkingDO parkingDO = new ParkingDO();
		parkingDO.setParkingCard(this.parkingCard);
		parkingDO.setVillageId(this.villageId);
		parkingDO.setParkingTypeId(this.parkingTypeId);
		parkingDO.setParkingName(this.parkingName);
		parkingDO.setCarNo(carNo);
		parkingDO.setMemo(memo);
		parkingDO.setOwnerType(ownerType);
		parkingDO.setOwnerId(ownerId);
		parkingDO.setBuyed(buyed);
		parkingDO.setSuiteId(suiteId);
		if(StringUtils.hasText(gmtStart)){
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
			try {
				Date parse = simpleDateFormat.parse(gmtStart);
				parkingDO.setGmtStart(parse);
			} catch (ParseException e) {
				throw new RuntimeException(e);
			}

		}
		if(StringUtils.hasText(gmtEnd)){
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
			try {
				Date parse = simpleDateFormat.parse(gmtEnd);
				parkingDO.setGmtEnd(parse);
			} catch (ParseException e) {
				throw new RuntimeException(e);
			}

		}
		return parkingDO;
	}

	public Long getParkingTypeId() {
		return parkingTypeId;
	}

	public void setParkingTypeId(Long parkingTypeId) {
		this.parkingTypeId = parkingTypeId;
	}

	public String getParkingName() {
		return parkingName;
	}

	public void setParkingName(String parkingName) {
		this.parkingName = parkingName;
	}

	public Long getVillageId() {
		return villageId;
	}

	public void setVillageId(Long villageId) {
		this.villageId = villageId;
	}

	public String getOwnerType() {
		return ownerType;
	}

	public void setOwnerType(String ownerType) {
		this.ownerType = ownerType;
	}

	public Long getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(Long ownerId) {
		this.ownerId = ownerId;
	}

	public String getParkingCard() {
		return parkingCard;
	}

	public void setParkingCard(String parkingCard) {
		this.parkingCard = parkingCard;
	}

	public String getCarNo() {
		return carNo;
	}

	public void setCarNo(String carNo) {
		this.carNo = carNo;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public String getGmtStart() {
		return gmtStart;
	}

	public void setGmtStart(String gmtStart) {
		this.gmtStart = gmtStart;
	}

	public String getGmtEnd() {
		return gmtEnd;
	}

	public void setGmtEnd(String gmtEnd) {
		this.gmtEnd = gmtEnd;
	}

	public Long getSuiteId() {
		return suiteId;
	}

	public void setSuiteId(Long suiteId) {
		this.suiteId = suiteId;
	}

	public Long getUnitId() {
		return unitId;
	}

	public void setUnitId(Long unitId) {
		this.unitId = unitId;
	}

	public Long getBuildingId() {
		return buildingId;
	}

	public void setBuildingId(Long buildingId) {
		this.buildingId = buildingId;
	}
}
